<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android 14 Launcher 数据加载分析（二） | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android 14 Launcher 数据加载分析（二）">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 14 Launcher 数据加载分析（二）">
<meta property="og:url" content="http://longzhiye.top/2024/02/16/2024-02-16/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android 14 Launcher 数据加载分析（二）">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-02-15T16:00:00.000Z">
<meta property="article:modified_time" content="2024-08-29T02:40:34.923Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="framework">
<meta property="article:tag" content="Launcher">
<meta name="twitter:card" content="summary">

  <meta name="keywords" content=",Android,framework,Launcher">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2024/02/16/2024-02-16/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2024/02/16/2024-02-16/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-13.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android 14 Launcher 数据加载分析（二）</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2024-02-16 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2024/02/16/2024-02-16/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android 14 Launcher 数据加载分析（二）&url=http://longzhiye.top/2024/02/16/2024-02-16/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android 14 Launcher 数据加载分析（二）&url=http://longzhiye.top/2024/02/16/2024-02-16/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2024/02/16/2024-02-16/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2024/02/16/2024-02-16/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2024/02/16/2024-02-16/&title=Android 14 Launcher 数据加载分析（二）" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android 14 Launcher 数据加载分析（二）&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2024/02/16/2024-02-16/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2024/02/16/2024-02-16/&text=Android 14 Launcher 数据加载分析（二）" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>前面一篇 launcher 基础认识中，有分析到 Launcher.java 这个类，在该类的 onCreate() 方法中，有 launcher 布局相关的初始化。这里还是从 onCreate() 方法出发，进行深入。<br> 说到数据加载，就不得不提到 <strong>launcher#onCreate()</strong> 方法，上篇说到该方法里面有布局相关的初始化，也是在  <strong>launcher#onCreate()</strong> 方法开始的。<br>先看 <strong>launcher#onCreate()</strong> 的部分代码：<br><strong>packages/apps/Launcher3/src/com/android/launcher3/Launcher.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">(Bundle savedInstanceState)</span> &#123;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 初始化View，进行各种View的初始化事件绑定</span></span><br><span class="line">    setupViews();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 加载、绑定数据（这里与之前版本的 startLoader() 作用一样）</span></span><br><span class="line">    <span class="comment">// 重点关注 addCallbacksAndLoad()</span></span><br><span class="line">    <span class="keyword">if</span> (!mModel.addCallbacksAndLoad(<span class="built_in">this</span>)) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!internalStateHandled) &#123;</span><br><span class="line">            Log.d(BAD_STATE, <span class="string">&quot;Launcher onCreate not binding sync, prevent drawing&quot;</span>);</span><br><span class="line">            <span class="comment">// If we are not binding synchronously, pause drawing until initial bind complete,</span></span><br><span class="line">            <span class="comment">// so that the system could continue to show the device loading prompt</span></span><br><span class="line">            mOnInitialBindListener = Boolean.FALSE::booleanValue;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">        <span class="comment">// 省略部分代码......</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上述代码调用了 <strong>LauncherModel</strong> 中的 <strong>addCallbacksAndLoad()</strong> 方法，一起看 <strong>LauncherModel#addCallbacksAndLoad()</strong> ：<br><strong>packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">addCallbacksAndLoad</span><span class="params">(Callbacks callbacks)</span> &#123;</span><br><span class="line">    <span class="keyword">synchronized</span> (mLock) &#123;</span><br><span class="line">        addCallbacks(callbacks);</span><br><span class="line">        <span class="comment">// 重点关注</span></span><br><span class="line">        <span class="keyword">return</span> startLoader(<span class="keyword">new</span> <span class="title class_">Callbacks</span>[] &#123; callbacks &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 该方法是加载程序的启动，在启动过程中并对于数据进行尝试同步绑定，</span></span><br><span class="line"><span class="comment">// 若能够进行绑定则可以返回true，在实现的过程中调用的是工作线程LoaderTask</span></span><br><span class="line"><span class="keyword">private</span> <span class="type">boolean</span> <span class="title function_">startLoader</span><span class="params">(Callbacks[] newCallbacks)</span> &#123;</span><br><span class="line">    <span class="comment">// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems</span></span><br><span class="line">    ItemInstallQueue.INSTANCE.get(mApp.getContext())</span><br><span class="line">            .pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);</span><br><span class="line">    <span class="keyword">synchronized</span> (mLock) &#123;</span><br><span class="line">        <span class="comment">// 对于旧的运行项进行一个清除</span></span><br><span class="line">        <span class="type">boolean</span> <span class="variable">wasRunning</span> <span class="operator">=</span> stopLoader();</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">bindDirectly</span> <span class="operator">=</span> mModelLoaded &amp;&amp; !mIsLoaderTaskRunning;</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">bindAllCallbacks</span> <span class="operator">=</span> wasRunning || !bindDirectly || newCallbacks.length == <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">final</span> Callbacks[] callbacksList = bindAllCallbacks ? getCallbacks() : newCallbacks;</span><br><span class="line">        <span class="keyword">if</span> (callbacksList.length &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="comment">// 在同步加载过程中对于所有挂起的绑定可运行项进行清除</span></span><br><span class="line">            <span class="keyword">for</span> (Callbacks cb : callbacksList) &#123;</span><br><span class="line">                MAIN_EXECUTOR.execute(cb::clearPendingBinds);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="type">LoaderResults</span> <span class="variable">loaderResults</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">LoaderResults</span>(</span><br><span class="line">                    mApp, mBgDataModel, mBgAllAppsList, callbacksList);</span><br><span class="line">            <span class="keyword">if</span> (bindDirectly) &#123;</span><br><span class="line">                <span class="comment">// 此处为数据恢复机制，例如：子用户切换到住用户时，会走到这一分支</span></span><br><span class="line">                <span class="comment">// 将同步项绑定于workspace、allapps、快捷方式、桌面小组件</span></span><br><span class="line">                loaderResults.bindWorkspace(bindAllCallbacks);</span><br><span class="line">                loaderResults.bindAllApps();</span><br><span class="line">                loaderResults.bindDeepShortcuts();</span><br><span class="line">                loaderResults.bindWidgets();</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// 数据加载，首次启动时 mModelLoaded 为 false，会走到这一分支</span></span><br><span class="line">                stopLoader();  <span class="comment">// 当有加载任务正在运行时则进行其停止运行</span></span><br><span class="line">                <span class="comment">// 对于LocalderTask进行启动：</span></span><br><span class="line">                mLoaderTask = <span class="keyword">new</span> <span class="title class_">LoaderTask</span>(</span><br><span class="line">                        mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);</span><br><span class="line">                <span class="comment">// 发布加载程序任务</span></span><br><span class="line">                MODEL_EXECUTOR.post(mLoaderTask);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上述代码，我们重点关注 LoaderTask.java ，分析数据如何加载，先看 LoaderTask 的构造方法 <strong>LoaderTask.java</strong> ：</p>
<p><strong>packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">LoaderTask</span><span class="params">(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel,</span></span><br><span class="line"><span class="params">        ModelDelegate modelDelegate, LoaderResults results)</span> &#123;</span><br><span class="line">    mApp = app;</span><br><span class="line">    mBgAllAppsList = bgAllAppsList;</span><br><span class="line">    mBgDataModel = dataModel;</span><br><span class="line">    mModelDelegate = modelDelegate;</span><br><span class="line">    mResults = results;</span><br><span class="line">    <span class="comment">// LauncherApps：用于检索当前用户和任何关联的托管配置文件的可启动活动列表的类。 这主要是供发射器使用的。 应用程序可以查询每个用户配置文件。</span></span><br><span class="line">    <span class="comment">// 由于PackageManager不会为其他配置文件传送包广播，因此您可以在此注册包更改。要监视正在添加或删除的托管配置文件，请注册以下广播： ACTION_MANAGED_PROFILE_ADDED、ACTION_MANAGED_PROFILE_REMOVED；</span></span><br><span class="line">    <span class="comment">// 从 Android O 开始，托管配置文件中的应用程序不再允许访问主配置文件中的应用程序。应用程序只能访问 &#123;@link getProfiles()&#125; 返回的配置文件。</span></span><br><span class="line">    mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class);</span><br><span class="line">    <span class="comment">// 与多用户相关，在多用户系统上管理用户和用户详细信息。</span></span><br><span class="line">    mUserManager = mApp.getContext().getSystemService(UserManager.class);</span><br><span class="line">    mUserCache = UserCache.INSTANCE.get(mApp.getContext());</span><br><span class="line">    <span class="comment">// 跟踪应用安装会话的实用程序类</span></span><br><span class="line">    mSessionHelper = InstallSessionHelper.INSTANCE.get(mApp.getContext());      </span><br><span class="line">    <span class="comment">// 获取 图标管理工具 对象</span></span><br><span class="line">    mIconCache = mApp.getIconCache();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>接着看 <strong>LoaderTask#run()</strong> ：<br><strong>packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">synchronized</span> (<span class="built_in">this</span>) &#123;</span><br><span class="line">        <span class="comment">// 如果已经停止，则快速跳过</span></span><br><span class="line">        <span class="keyword">if</span> (mStopped) &#123;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="type">Object</span> <span class="variable">traceToken</span> <span class="operator">=</span> TraceHelper.INSTANCE.beginSection(TAG);</span><br><span class="line">    <span class="type">TimingLogger</span> <span class="variable">logger</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">TimingLogger</span>(TAG, <span class="string">&quot;run&quot;</span>);</span><br><span class="line">    <span class="type">LoaderMemoryLogger</span> <span class="variable">memoryLogger</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">LoaderMemoryLogger</span>();</span><br><span class="line">    <span class="comment">// 这里与 LauncherModel.LoaderTransaction 关联上</span></span><br><span class="line">    <span class="keyword">try</span> (LauncherModel.<span class="type">LoaderTransaction</span> <span class="variable">transaction</span> <span class="operator">=</span> mApp.getModel().beginLoader(<span class="built_in">this</span>)) &#123;</span><br><span class="line">        List&lt;ShortcutInfo&gt; allShortcuts = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        Trace.beginSection(<span class="string">&quot;LoadWorkspace&quot;</span>);</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">// 第一步：加载工作区。****重点关注****</span></span><br><span class="line">            loadWorkspace(allShortcuts, memoryLogger);</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            Trace.endSection();</span><br><span class="line">        &#125;</span><br><span class="line">        logASplit(logger, <span class="string">&quot;loadWorkspace&quot;</span>);</span><br><span class="line">        <span class="comment">// 根据从数据库加载的工作空间，清理数据重新同步小部件快捷方式。</span></span><br><span class="line">        <span class="comment">// 如果桌面(workspace)是从 不变设备配置文件中定义的主数据库不同的数据库加载的，则不应调用 sanitizeData。 </span></span><br><span class="line">        <span class="comment">// 例如，网格预览和最小设备模式都使用不同的数据库</span></span><br><span class="line">        <span class="comment">// mDbName 在 loadWorkspace() 方法里赋值</span></span><br><span class="line">        <span class="keyword">if</span> (mApp.getInvariantDeviceProfile().dbFile.equals(mDbName)) &#123;</span><br><span class="line">            verifyNotStopped();</span><br><span class="line">            sanitizeData();</span><br><span class="line">            logASplit(logger, <span class="string">&quot;sanitizeData&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 绑定 workspace</span></span><br><span class="line">        mResults.bindWorkspace(<span class="literal">true</span> <span class="comment">/* incrementBindId */</span>);</span><br><span class="line">        logASplit(logger, <span class="string">&quot;bindWorkspace&quot;</span>);</span><br><span class="line">        mModelDelegate.workspaceLoadComplete();</span><br><span class="line">        <span class="comment">// 发送首屏广播。</span></span><br><span class="line">        sendFirstScreenActiveInstallsBroadcast();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;sendFirstScreenActiveInstallsBroadcast&quot;</span>);</span><br><span class="line">        <span class="comment">// 等待桌面(workspace)加载完成再加载抽屉(AllApps)</span></span><br><span class="line">        waitForIdle();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;step 1 complete&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 第二步：</span></span><br><span class="line">        Trace.beginSection(<span class="string">&quot;LoadAllApps&quot;</span>);</span><br><span class="line">        List&lt;LauncherActivityInfo&gt; allActivityList;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">// 加载所有应用App</span></span><br><span class="line">            allActivityList = loadAllApps();</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            Trace.endSection();</span><br><span class="line">        &#125;</span><br><span class="line">        logASplit(logger, <span class="string">&quot;loadAllApps&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 绑定 AllApps</span></span><br><span class="line">        mResults.bindAllApps();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;bindAllApps&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 关于 IconCacheUpdateHandler  文章后面有补充。</span></span><br><span class="line">        <span class="type">IconCacheUpdateHandler</span> <span class="variable">updateHandler</span> <span class="operator">=</span> mIconCache.getUpdateHandler();</span><br><span class="line">        setIgnorePackages(updateHandler);</span><br><span class="line">        updateHandler.updateIcons(allActivityList,</span><br><span class="line">                LauncherActivityCachingLogic.newInstance(mApp.getContext()),</span><br><span class="line">                mApp.getModel()::onPackageIconsUpdated);</span><br><span class="line">        logASplit(logger, <span class="string">&quot;update icon cache&quot;</span>);</span><br><span class="line">        <span class="keyword">if</span> (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) &#123;</span><br><span class="line">            verifyNotStopped();</span><br><span class="line">            logASplit(logger, <span class="string">&quot;save shortcuts in icon cache&quot;</span>);</span><br><span class="line">            <span class="comment">// 将对应图标进行缓存</span></span><br><span class="line">            updateHandler.updateIcons(allShortcuts, <span class="keyword">new</span> <span class="title class_">ShortcutCachingLogic</span>(),</span><br><span class="line">                    mApp.getModel()::onPackageIconsUpdated);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 等待上一操作加载完成，在进行加载应用程序快捷方式</span></span><br><span class="line">        waitForIdle();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;step 2 complete&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 第三步：加载应用程序快捷方式</span></span><br><span class="line">        List&lt;ShortcutInfo&gt; allDeepShortcuts = loadDeepShortcuts();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;loadDeepShortcuts&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 数据同步绑定应用程序快捷方式</span></span><br><span class="line">        mResults.bindDeepShortcuts();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;bindDeepShortcuts&quot;</span>);</span><br><span class="line">        <span class="keyword">if</span> (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) &#123;</span><br><span class="line">            verifyNotStopped();</span><br><span class="line">            logASplit(logger, <span class="string">&quot;save deep shortcuts in icon cache&quot;</span>);</span><br><span class="line">            <span class="comment">// 缓存对应图标</span></span><br><span class="line">            updateHandler.updateIcons(allDeepShortcuts,</span><br><span class="line">                    <span class="keyword">new</span> <span class="title class_">ShortcutCachingLogic</span>(), (pkgs, user) -&gt; &#123; &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 等待上一操作加载完成，在进行加载小部件等</span></span><br><span class="line">        waitForIdle();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;step 3 complete&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 第四步：加载桌面小部件</span></span><br><span class="line">        List&lt;ComponentWithLabelAndIcon&gt; allWidgetsList =</span><br><span class="line">                mBgDataModel.widgetsModel.update(mApp, <span class="literal">null</span>);</span><br><span class="line">        logASplit(logger, <span class="string">&quot;load widgets&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        <span class="comment">// 绑定 Widgets</span></span><br><span class="line">        mResults.bindWidgets();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;bindWidgets&quot;</span>);</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">            <span class="comment">// 将小部件进行缓存</span></span><br><span class="line">        updateHandler.updateIcons(allWidgetsList,</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">ComponentWithIconCachingLogic</span>(mApp.getContext(), <span class="literal">true</span>),</span><br><span class="line">                mApp.getModel()::onWidgetLabelsUpdated);</span><br><span class="line">        logASplit(logger, <span class="string">&quot;save widgets in icon cache&quot;</span>);</span><br><span class="line">        <span class="comment">// 第五步</span></span><br><span class="line">        <span class="keyword">if</span> (FeatureFlags.FOLDER_NAME_SUGGEST.get()) &#123;</span><br><span class="line">            <span class="comment">// 加载文件夹名称</span></span><br><span class="line">            loadFolderNames();</span><br><span class="line">        &#125;</span><br><span class="line">        verifyNotStopped();</span><br><span class="line">        updateHandler.finish();</span><br><span class="line">        logASplit(logger, <span class="string">&quot;finish icon update&quot;</span>);</span><br><span class="line">        mModelDelegate.modelLoadComplete();</span><br><span class="line">        <span class="comment">// 提交完成。</span></span><br><span class="line">        transaction.commit();</span><br><span class="line">        memoryLogger.clearLogs();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (CancellationException e) &#123;</span><br><span class="line">        <span class="comment">// Loader stopped, ignore</span></span><br><span class="line">        logASplit(logger, <span class="string">&quot;Cancelled&quot;</span>);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        memoryLogger.printLogs();</span><br><span class="line">        <span class="keyword">throw</span> e;</span><br><span class="line">    &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">        logger.dumpToLog();</span><br><span class="line">    &#125;</span><br><span class="line">    TraceHelper.INSTANCE.endSection(traceToken);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上述 <strong>LoaderTask#run()</strong> 代码可以清晰的看到每一步操作所要做的工作。 <strong>loadWorkspace()</strong> 和 <strong>bindWorkspace()</strong> ，也就是加载 <strong>workspace</strong> 的应用并且进行绑定， <strong>waitForIdle()</strong> 方法主要是等待加载数据结束。 <strong>sendFirstScreenActiveInstallsBroadcast()</strong> 发送首屏广播。 <strong>loadAllApps()</strong> 和 <strong>bindAllApps()</strong> 加载并绑定所有的 APP 信息， <strong>loadDeepShortcuts()</strong> 和 <strong>bindDeepShortcuts()</strong> 加载并绑定所有的快捷方式，然后加载并绑定所有的小部件。至此launcher数据加载基本就完成了。<br><strong>补充</strong>：上述代码出现比较多的 <strong>IconCacheUpdateHandler</strong> 。</p>
<blockquote>
<p>IconCacheUpdateHandler：用于处理图标缓存更新的实用程序类。<br>IconCacheUpdateHandler#updateIcons()： 更新持久数据库，以便只有与应用程序相对应的条目保留在数据库中并进行更新。</p>
</blockquote>

      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2024/02/16/2024-02-16/">http://longzhiye.top/2024/02/16/2024-02-16/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/Launcher/" rel="tag">Launcher</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2024/02/17/2024-02-17/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 14 Launcher 数据库及Workspace的数据加载与绑定（三）'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2024/02/15/2024-02-15/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 14 Launcher 基础认识(一)'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
